{template 'header'}
<style type="text/css">
.my-student-card-page .student-outer {
    width:320px;
    height:100vh;
    -webkit-box-pack:center;
    -webkit-justify-content:center;
    -ms-flex-pack:center;
    justify-content:center;
    -webkit-align-items:center;
    -webkit-box-align:center;
    -ms-flex-align:center;
    align-items:center;
    margin:0 auto;
    -webkit-flex-direction:column;
    -ms-flex-direction:column;
    flex-direction:column;
    overflow:hidde;
}
.my-student-card-page .student-inner {
    width:306px;
    height:418px;
    position:relative;
    -webkit-transform-style:preserve-3d;
    -ms-transform-style:preserve-3d;
    transform-style:preserve-3d;
    -webkit-transform:rotateX(6deg);
    -ms-transform:rotateX(6deg);
    transform:rotateX(6deg);
    box-shadow:1px 1px 6px 1px rgba(255, 68, 84, 0.1);
    border-radius:20px;
}
.my-student-card-page .student-inner .student-cover {
    width:100%;
    height:100%;
    position:absolute;
    -webkit-transform-origin:left;
    -ms-transform-origin:left;
    transform-origin:left;
    -webkit-transform-style:preserve-3d;
    -ms-transform-style:preserve-3d;
    transform-style:preserve-3d;
    -webkit-backface-visibility:hidden;
    backface-visibility:hidden;
    z-index:2;
    border-radius:20px;
    overflow:hidden;
}
.my-student-card-page .student-inner .student-cover img {
    width:100%;
}
.my-student-card-page .student-inner .student-cover p {
    font-size:0.22rem;
    color:#fff;
    font-weight:500;
    -webkit-letter-spacing:1px;
    -moz-letter-spacing:1px;
    -ms-letter-spacing:1px;
    letter-spacing:1px;
    position:absolute;
    top:70px;
    width:100%;
    text-align:center;
}
.my-student-card-page .student-inner .student-card {
    width:306px;
    height:100%;
    position:absolute;
    -webkit-transform-origin:left;
    -ms-transform-origin:left;
    transform-origin:left;
    -webkit-transform-style:preserve-3d;
    -ms-transform-style:preserve-3d;
    transform-style:preserve-3d;
    -webkit-backface-visibility:hidden;
    backface-visibility:hidden;
    border-radius:20px;
    overflow:hidden;
}
.my-student-card-page .student-inner .student-card img {
    width:100%;
}
.my-student-card-page .toOpenTip {
    width:100%;
    font-size:0.18rem;
    color:#4a4a4a;
    text-align:center;
    margin-top:-0.3rem;
    position:relative;
}
.my-student-card-page .toOpenTip img {
    width:0.5rem;
}
.my-student-card-page .toShareTip {
    width:100%;
    height:30px;
    font-size:0.18rem;
    color:#4a4a4a;
    text-align:center;
    margin-top:0.4rem;
}
</style>
<div id="root">
    <div class="g-page my-student-card-page">
        <div class="g-flex student-outer">
            <div class="student-inner">
                <div class="student-cover" style="animation: pageTurning 1.5s linear 1 forwards;">
                    <img src="{$img}">
                    <p id="book-title"></p>
                </div>
                <div class="student-card">
                    <div style="display:none;">
                        <img id="book-mem-res" src="">
                    </div>
                </div>
            </div>
            <div class="toShareTip">长按保存图片，可分享给好友</div>
        </div>
    </div>
</div>
<canvas id="myCanvas" width="640" height="1008" style="display:none;"></canvas>  
<script>
var mem_book_id = getCookie('mem_book');
function getInfo(){
	$.ajax({
		url:'{php echo $this->murl("mysid")}',
		data: {bid: mem_book_id},
		type: "post",
		success: function(dat){
			dat = JSON.parse(dat);
			if(dat.code==1){
				createPoster(dat.poster)
				$('#book-title').text(dat.poster.btitle);
			}
			else{
				msgTip(dat.msg,function(){
					location.href='{php echo $this->murl("index")}'
				})
			}
		}
	});
}
var nickname = '{$mem["nickname"]}'
function createPoster(poster){
	sysPoster = poster.poster.data;
	var avatar_pic = new Image();
	avatar_pic.src = '{$mem["avatar"]}';
	avatar_pic.onload = function(e) {
		var qr_pic = new Image();
		qr_pic.src = poster.qurl;
		qr_pic.onload = function(e) {
			var canvas = document.getElementById("myCanvas");
			var cxt = canvas.getContext("2d");
			
			var bg_pic = new Image();
			bg_pic.src = poster.poster.bg;
			bg_pic.onload = function(e) {
				cxt.drawImage(bg_pic, 0, 0, 640, 1008);
				for(var ii in sysPoster){
					var pData = sysPoster[ii];
					pData.left = pData.left.replace('px', '');
			  		pData.top = pData.top.replace('px', '');
			      	pData.width = pData.width.replace('px', '');
			      	pData.height = pData.height.replace('px', '');
			      	pData.left = parseFloat(pData.left) * 2;
			      	pData.top = parseFloat(pData.top) * 2;
			      	pData.width = parseFloat(pData.width) * 2;
			      	pData.height = parseFloat(pData.height) * 2;
			      	if(pData.size) {
			      		pData.size = pData.size.replace('px', '');
			      		pData.size = parseFloat(pData.size) * 2;
			      	}
			      	if(pData.type=='img'){
						cxt.drawImage(avatar_pic, pData.left, pData.top, pData.width, pData.height);
					}
					else if(pData.type=='qr'){
						cxt.drawImage(qr_pic, pData.left, pData.top, pData.width, pData.height);
					}
					else if(pData.type=='name'){
						cxt.fillStyle = pData.color; //设置描边样式
					    cxt.font = pData.size+"px Arial"; //设置字体大小和字体
					    var trueTop = 0;
					    trueTop = parseFloat(pData.top) + parseInt(pData.size);
					    cxt.fillText(nickname, pData.left, trueTop);
					}
					else if(pData.type=='book'){
						cxt.fillStyle = pData.color; //设置描边样式
					    cxt.font = pData.size+"px Arial"; //设置字体大小和字体
					    var trueTop = 0;
					    trueTop = parseFloat(pData.top) + parseInt(pData.size);
					    cxt.fillText(poster.btitle, pData.left, trueTop);
					}
					else if(pData.type=='sid'){
						cxt.fillStyle = pData.color; //设置描边样式
					    cxt.font = pData.size+"px Arial"; //设置字体大小和字体
					    var trueTop = 0;
					    trueTop = parseFloat(pData.top) + parseInt(pData.size);
					    cxt.fillText(poster.studentid, pData.left, trueTop);
					}
					else if(pData.type=='sday'){
						cxt.fillStyle = pData.color; //设置描边样式
					    cxt.font = pData.size+"px Arial"; //设置字体大小和字体
					    var trueTop = 0;
					    trueTop = parseFloat(pData.top) + parseInt(pData.size);
					    cxt.fillText(poster.class_num, pData.left, trueTop);
					}
				}
				var u = navigator.userAgent, app = navigator.appVersion;
		    	var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
		    	var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
		    	if(isIOS){
		    		var src = canvas.toDataURL().replace("data:image/png;base64,","");
		    	}
		    	isAndroid = true;
		    	if(isAndroid){
		    		var src = canvas.toDataURL("image/png");
		    	}
		    	$('#book-mem-res').attr('src', src);
		    	$('#book-mem-res').parent('div').show();
			}
		}
	}
}
$(function(){
	getInfo();
})
</script>

</body></html>